package 无重复字符的最长子串;

import java.util.HashSet;

public class Solution {

    // 考虑使用双指针，或者双端队列的形式，保证队列内元素不重复，用hashset可以保存不重复子串

    int maxLength = Integer.MIN_VALUE;

    public int lengthOfLongestSubstring(String s) {
        int len = s.length();
        HashSet<Character> occ = new HashSet<>();

        if(len==0){
            return 0;
        }
        int left = 0,right=1;
        occ.add(s.charAt(left));
        while(right<len){
            while(occ.contains(s.charAt(right))){
                occ.remove(s.charAt(left));
                left++;
            }
            occ.add(s.charAt(right));
            right++;
            maxLength = Math.max(occ.size(),maxLength);
        }
        return maxLength;
    }
}
